#include <iostream>
#include <string>
#include <fstream>
#include "bundle.h"

int main(int argc, char *argv[])
{
    std::cout << "argv[1] 是原文件的路径名称\n";
    std::cout << "argv[2] 是压缩后文件的路径名称\n";

    if (argc < 3)
        return -1;

    std::string iffilename = argv[1];
    std::string offilename = argv[2];

    std::ifstream ifs;
    ifs.open(iffilename, std::ios::binary);
    // 跳到文件末尾
    ifs.seekg(0, std::ios::end);
    // 计算文件大小
    size_t fsize = ifs.tellg();
    // 回到文件的起始位置
    ifs.seekg(0, std::ios::beg);
    std::string body;
    body.resize(fsize);
    ifs.read(&body[0], fsize);

    std::string packed = bundle::pack(bundle::LZIP, body);

    std::ofstream ofs;
    ofs.open(offilename, std::ios::binary);
    ofs.write(&packed[0], packed.size());

    ifs.close();
    ofs.close();

    return 0;
}